package com.basic.modules.nykf.controller;

import com.basic.common.annotation.StringTrim;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.R;
import com.basic.modules.nykf.entity.CustomerEntity;
import com.basic.modules.nykf.entity.CustomerFpEntity;
import com.basic.modules.nykf.service.CustomerService;
import com.basic.modules.nykf.service.PermissionService;
import com.basic.modules.sys.controller.AbstractController;
import com.basic.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * 客户管理
 *
 * @author zeo
 */
@RestController
@RequestMapping("new/ykf/customer")
public class CustomerController extends AbstractController {

    @Autowired
    CustomerService customerService;

    @Autowired
    PermissionService permissionService;

    /**
     * 列表-分页
     */
    @StringTrim
    @PostMapping("/getCustomerList")
    public R getCustomerList(@RequestBody ParamsModel<CustomerEntity> params) {
        PageUtils page = customerService.getCustomerList(params);
        return R.ok(page);
    }

    /**
     * 新增客户及店铺
     *
     * @param customerEntity
     * @return
     */
    @PostMapping("/addCustomerAndShop")
    public R addCustomerAndShop(@RequestBody CustomerEntity customerEntity) {
        return customerService.addCustomerAndShop(customerEntity);
    }

    /**
     * 修改客户及店铺
     *
     * @param customerEntity
     * @return
     */
    @PostMapping("/editCustomerAndShop")
    public R editCustomerAndShop(@RequestBody CustomerEntity customerEntity) {
        return customerService.editCustomerAndShop(customerEntity);
    }

    /**
     * 获取店铺对接人集合
     *
     * @return
     */
    @PostMapping("/getUserListByRoleId")
    public R getUserListByRoleId(@RequestBody Map map) {
        Long roleId = Long.parseLong(map.get("roleId").toString());
        List<SysUserEntity> sysUserEntityList = permissionService.getUserListByRoleId(roleId);
        return R.ok(sysUserEntityList);
    }

    /**
     * 添加或编辑客户发票
     *
     * @param customerFpEntity
     * @return
     */
    @PostMapping("/addCustomerFpInfo")
    public R addCustomerFpInfo(@RequestBody CustomerFpEntity customerFpEntity) {
        return customerService.addCustomerFpInfo(customerFpEntity);
    }

    /**
     * 根据客户ID查询发票数据
     * @param customerEntity
     * @return
     */
    @PostMapping("/getFpListByCustomerId")
    public R getFpListByCustomerId(@RequestBody CustomerEntity customerEntity) {
        return R.ok(customerService.getFpListByCustomerId(customerEntity));
    }
}